//
//  MyTableViewCell.m
//  Project_A
//
//  Created by 房磊 on 15/1/15.
//  Copyright (c) 2015年 Flowers. All rights reserved.
//

#import "MyTableViewCell.h"

@implementation MyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:254/256.0 green:246/256.0 blue:226/256.0 alpha:0.5];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self creatSubView];
    }
    
    
    return self;
}

- (void)creatSubView
{
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(10, 5, 100, 120)];
    self.image.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.image];
    self.nameLab = [self creatLabelFrame:CGRectMake(130, 10, 200, 30) text:@"标题"];
    self.nameLab.font = [UIFont systemFontOfSize:15.0];
    [self.contentView addSubview:self.nameLab];
    self.playNumLab = [self creatLabelFrame:CGRectMake(130, 35, 200, 30) text:@"播放次数"];
    self.playNumLab.font = [UIFont systemFontOfSize:12.0];
    [self.contentView addSubview:self.playNumLab];
    self.introduceLab = [self creatLabelFrame:CGRectMake(130, 60, 240, 70) text:@"简介"];
    self.introduceLab.font = [UIFont systemFontOfSize:12.0];
    self.introduceLab.numberOfLines = 0;
    [self.contentView addSubview:self.introduceLab];
    
}

- (void)setModel:(FindModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    self.nameLab.text = model.albumName;
    self.playNumLab.text = [NSString stringWithFormat:@"%@ %@ %@", @"播放次数:",model.albumPlayNum,@"次"];
    NSURL *url = [NSURL URLWithString:model.albumBigPic];
    [self.image sd_setImageWithURL:url];
    //赋值并自适应高度
    self.introduceLab.text = [NSString stringWithFormat:@"%@ %@", @"简介:", model.albumIntroduction];
//    CGFloat labelHeight = [[self class] heightForContent:_model.albumIntroduction];
//    CGRect frame = self.introduceLab.frame;
//    
//    frame.size.height = labelHeight;
//    self.introduceLab.frame = frame;
    
    
    
}


+ (CGFloat)heightForContent:(NSString *)text
{
    CGSize size = CGSizeMake(240, 2000);
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15.0] forKey:NSFontAttributeName];
      CGRect frame = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return frame.size.height;
    
    
}












- (UILabel *)creatLabelFrame:(CGRect)frame text:(NSString *)text
{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.backgroundColor = [UIColor clearColor];
    label.text = text;
    return [label autorelease];
}




- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
